package com.base.cn.platform.os.common.logger;

import com.base.cn.platform.os.common.utils.DateUtils;
import com.base.cn.platform.os.common.utils.web.WebUtils;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;

/**
 * PVUV日志对象
 *
 * @author s.li
 * @date 2019/03/22
 */
@Slf4j
public class PageViewLogger {

    /**
     * 生成PV日志
     * @param request HttpServletRequest
     * @param form 访问来源
     */
    public static synchronized void genPvUvLog(HttpServletRequest request, String form, BigDecimal tenantId){
        StringBuilder loginContext = new StringBuilder();
        String ip = WebUtils.getIpAddr(request);
        loginContext.append(ip).append("|").append(form).append("|").append(DateUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss")).append("|").append(tenantId);
        log.info(loginContext.toString());
    }
}
